from stacking.loader.processing.sim.simulation import SimObserver

        
class CraneCapacity(SimObserver):
    """This observer computes the maximum number of items that any crane is carrying at any given 
    time. This value is used as the capacity of all cranes in the CS problem."""
    def init(self, warehouse):
        SimObserver.init(self, warehouse)
        self.max_capacity = 1
        
    def pre_execute(self, crane, action):
        N = len(crane.items) + (len(action.items) if action.is_pickup else 0)
        self.max_capacity = max(self.max_capacity, N)
        
    def end(self):
        return self.max_capacity
        
